package fotobook;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.*;

import fotobook.data.File;
import fotobook.data.FileAccessService;
import fotobook.data.User;

@SuppressWarnings("serial")
public class FotobookServlet extends HttpServlet {

	public void doGet(final HttpServletRequest req,
			final HttpServletResponse resp) throws IOException {
		final User user = new User() {
			{
				this.id = "1";
			}

			private String id;

			@Override
			public String getId() {
				return id;
			}
		};
		final FileAccessService io = new FileAccessService(user);
		List<File> files = io.retrieveFiles();
		if (files.isEmpty()) {
			io.createFile(new File() {

				@Override
				public String getFilename() {
					return "test.docx";
				}
			});
			files = io.retrieveFiles();
		}
		resp.setContentType("text/plain");
		resp.getWriter().println(files);
	}
}
